/*
 * GdiplusSampleApplication.cpp
 *
 *  Created on: 2010-12-8
 *      Author: try
 */

#include "GdiplusSampleApplication.h"

GdiplusSampleApplication::GdiplusSampleApplication(HINSTANCE hInstance,
    HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) :
  SampleApplication(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  ,page(NULL)
  {
  WorkPage::startupGdiplus();
}

GdiplusSampleApplication::~GdiplusSampleApplication() {
  if (page)delete page;
  WorkPage::shutdownGdiplus();
}

LRESULT GdiplusSampleApplication::wndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
    LPARAM lParam) {
  return SampleApplication::wndProc(hwnd, uMsg, wParam, lParam);
}

void GdiplusSampleApplication::onPaint(){
  //刷新画布
  page->refresh();
}

void GdiplusSampleApplication::onMouseWheelEvent(int x, int y, int zDelta, unsigned int buttonsStatus){
  KeySequence ks;
  getKeySequence(ks);
  WheelEvent wheelEvent(x, y, zDelta, buttonsStatus, ks, Vertical, this);
  page->trackEvent(&wheelEvent);
  page->refresh(true);
}

void GdiplusSampleApplication::onMouseMove(int x, int y, unsigned int buttonsStatus){
  KeySequence ks;
  page->trackMouseEvent(MouseEvent::MoveType, x, y, buttonsStatus, getKeySequence(ks));
}

void GdiplusSampleApplication::onMouseLeftPress(int x, int y, unsigned int buttonsStatus){
  KeySequence ks;
  page->trackMouseEvent(MouseEvent::PressType, x, y, buttonsStatus, getKeySequence(ks));
}

void GdiplusSampleApplication::onMouseLeftRelease(int x, int y, unsigned int buttonsStatus){
  KeySequence ks;
  page->trackMouseEvent(MouseEvent::ReleaseType, x, y, buttonsStatus, getKeySequence(ks));
}

void GdiplusSampleApplication::onMouseLeftDoubleClick(int x, int y, unsigned int buttonsStatus){
  KeySequence ks;
  page->trackMouseEvent(MouseEvent::DoubleClickType, x, y, buttonsStatus, getKeySequence(ks));
}

void GdiplusSampleApplication::onMouseRightPress(int x, int y, unsigned int buttonsStatus){
  KeySequence ks;
  page->trackMouseEvent(MouseEvent::PressType, x, y, buttonsStatus, getKeySequence(ks));
}

void GdiplusSampleApplication::onMouseRightRelease(int x, int y, unsigned int buttonsStatus){
  KeySequence ks;
  page->trackMouseEvent(MouseEvent::ReleaseType, x, y, buttonsStatus, getKeySequence(ks));
}

void GdiplusSampleApplication::onKeyPress(int key){
  KeySequence ks;
  KeyEvent ke(KeyEvent::PressType, key, getKeySequence(ks));
  page->trackEvent(&ke);
  page->refresh(true);
}

void GdiplusSampleApplication::onKeyRelease(int key){

}

/**
 * 设置光标
 */
bool GdiplusSampleApplication::onSetCursor(){
  return page->refreshCursor();
}
